function a(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

function t(a, t, e, n, o, s) {
    var d = getApp(), l = d.configApp.url;
    e.s_id || (e.s_id = d.globalData.s_id), e.version = d.configApp.version, e.platform = d.configApp.platform, 
    e.appid = d.configApp.appid, e.appkey = "", e.sign = "", e.timestamp = new Date().getTime(), 
    wx.request({
        url: l + t,
        data: e,
        header: {
            "content-type": "application/x-www-form-urlencoded"
        },
        method: "POST",
        dataType: "json",
        success: function(t) {
            if (wx.hideLoading(), a.data.isloading && (a.data.isloading = !1), a.data.isposting && (a.data.isposting = !1), 
            a.data.pageloading && a.setData({
                pageloading: !1
            }), "function" == typeof n && 200 == t.statusCode && 200 == t.data.code) {
                if (-999 == t.data.result.status || -998 == t.data.result.status) return wx.clearStorage(), 
                getApp().globalData.s_id = "", getApp().globalData.presid = "", a.setData({
                    s_id: "",
                    pageloading: !1,
                    isloading: !1,
                    isposting: !1
                }), void wx.showToast({
                    icon: "none",
                    title: "登录状态已过期"
                });
                if (-996 == t.data.result.status) return void i();
                n(t.data.result);
            }
        },
        fail: function() {
            wx.hideLoading(), a.data.isloading && (a.data.isloading = !1), a.data.isposting && (a.data.isposting = !1), 
            a.data.pageloading && a.setData({
                pageloading: !1
            }), "function" == typeof o && (o(), wx.showToast({
                icon: "none",
                title: "网络请求失败！"
            }), a.setData({
                pageloading: !1,
                netfail: !0
            }));
        },
        complete: function() {}
    });
}

function e(t, e, n, o) {
    if (o && (t.data.dataMore = !0, wx.stopPullDownRefresh()), o && e.length <= 0 && t.setData({
        pageloading: !1,
        noneData: !0,
        showloadingmore: !1
    }), 0 == e.length) return t.data.dataMore = !1, t.setData({
        pageloading: !1,
        showloadingmore: !1
    }), void (o && ((i = new Array())[0] = e, t.setData({
        noneData: !0,
        pageloading: !1,
        listdata: i
    })));
    if (e.length < n && (t.data.dataMore = !1, t.setData({
        pageloading: !1,
        showloadingmore: !1
    })), o) {
        var i = new Array();
        i[0] = e, t.setData({
            noneData: !1,
            pageloading: !1,
            listdata: i
        });
    } else t.setData(a({}, "listdata[" + t.data.listdata.length + "]", e));
}

function n(t, e, n, o, i, s, d) {
    if (0 != e.length) if (e.length < n ? t.setData(a({
        pageloading: !1
    }, s, !1)) : t.setData(a({
        pageloading: !1
    }, s, !0)), d) {
        var l, g = new Array();
        g[0] = e, t.setData((l = {}, a(l, i, !1), a(l, o, g), l));
    } else t.setData(a({}, o + "[" + t.data[o].length + "]", e)); else if (d) {
        var p;
        t.setData((p = {
            pageloading: !1
        }, a(p, s, !1), a(p, i, !0), p));
    } else t.setData(a({
        pageloading: !1
    }, s, !1));
}

function o(a, e) {
    t(a, "message/addMsgCount", {
        tpl_ids: e.join()
    });
}

function i() {
    if (-1 == getApp().configApp.platform.indexOf("bdminapp")) {
        var a = wx.getUpdateManager();
        a.onUpdateReady(function() {
            console.log("发现新版本"), wx.showModal({
                title: "温馨提示",
                content: "发现新版本，马上更新最新版本吧？",
                confirmText: "好的",
                success: function(t) {
                    t.confirm ? a.applyUpdate() : t.cancel && console.log("取消更新");
                }
            });
        });
    }
}

module.exports = {
    request_post: t,
    request_post_chat: function(a, t, e, n, o, i) {
        var s = getApp(), d = s.configApp.urlChat;
        e.s_id || (e.s_id = s.globalData.s_id), e.version = s.configApp.version, e.platform = s.globalData.platform, 
        e.sign = "", e.timestamp = new Date().getTime(), e.appid = s.globalData.appid, e.appkey = "", 
        wx.request({
            url: d + t,
            data: e,
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            method: "POST",
            dataType: "json",
            success: function(t) {
                if (wx.hideLoading(), a.data.isloading && (a.data.isloading = !1), a.data.isposting && (a.data.isposting = !1), 
                a.data.pageloading && a.setData({
                    pageloading: !1
                }), "function" == typeof n && 200 == t.statusCode && 200 == t.data.code) {
                    if (-999 == t.data.result.status || -998 == t.data.result.status) return wx.clearStorage(), 
                    getApp().globalData.s_id = "", getApp().globalData.presid = "", a.setData({
                        s_id: "",
                        pageloading: !1,
                        isloading: !1,
                        isposting: !1
                    }), void wx.showToast({
                        icon: "none",
                        title: "登录状态已过期"
                    });
                    n(t.data.result);
                }
            },
            fail: function() {
                wx.hideLoading(), a.data.isloading && (a.data.isloading = !1), a.data.isposting && (a.data.isposting = !1), 
                a.data.pageloading && a.setData({
                    pageloading: !1
                }), "function" == typeof o && (o(), wx.showToast({
                    icon: "none",
                    title: "网络请求失败！"
                }), a.setData({
                    pageloading: !1,
                    netfail: !0
                }));
            },
            complete: function() {}
        });
    },
    getOnLoadData: function(a, e, n, o) {
        a.data.isloading || (a.data.isloading = !0, t(a, e, n, function(a) {
            "function" == typeof o && o(a);
        }));
    },
    getListData: function(a, n, o, i, s) {
        if (n || !a.data.noneData) {
            if (!a.data.isloading) {
                if (a.data.isloading = !0, n && !a.data.pageloading && wx.showLoading({
                    title: "加载中..."
                }), !n) {
                    if (!a.data.dataMore) return void (a.data.isloading = !1);
                    a.setData({
                        showloadingmore: !0
                    });
                }
                var d = "";
                !n && a.data.listdata.length > 0 && a.data.nexttime && (d = a.data.nexttime), i.time = d, 
                t(a, o, i, function(t) {
                    a.data.isloading = !1, wx.stopPullDownRefresh(), 1 == t.status && (a.data.nexttime = t.data.nexttime, 
                    e(a, t.data.data, t.data.count, n), "function" == typeof s && s(t));
                });
            }
        } else a.data.isloading = !1;
    },
    getListDataX: function(a, e, o, i, s, d, l, g, p) {
        if (!a.data.isloading) if (a.data.isloading = !0, e && a.data.pageloading, e || a.data[g]) {
            var r = "";
            !e && a.data[s].length > 0 && a.data[d] && (r = a.data[d]), i.time = r, t(a, o, i, function(t) {
                a.data.isloading = !1, wx.stopPullDownRefresh(), 1 == t.status && (a.data[d] = t.data.nexttime, 
                n(a, t.data.data, t.data.count, s, l, g, e), "function" == typeof p && p(t));
            });
        } else a.data.isloading = !1;
    },
    getItemID: function(a, t) {
        var e = a.data.listIndex, n = a.data.itemIndex;
        if (a.data.listdata.length > 0) var o = a.data.listdata[e][n][t];
        return o;
    },
    getPlatform: function(a) {
        var t = getApp().globalData.systemInfor;
        t ? a.setData({
            platform: t.platform
        }) : wx.getSystemInfoSync({
            success: function(t) {
                getApp().globalData.systemInfor = t;
                var e = t;
                a.setData({
                    platform: e.platform
                });
            }
        });
    },
    getImgHeight: function(a, t, e) {
        wx.getSystemInfo({
            success: function(n) {
                var o = (n.windowWidth - t) * e;
                o && a.setData({
                    imgHeight: o
                });
            }
        });
    },
    checkIsLogin: function(a) {
        return !!getApp().globalData.sid || (wx.navigateTo({
            url: a
        }), !1);
    },
    initQiniu: function(a) {
        var t = getApp(), e = {
            region: "ECN",
            uptokenURL: t.configApp.qiniu_uptoken_url,
            domain: t.configApp.qiniuDomain,
            shouldUseQiniuFileName: !0
        };
        a.init(e);
    },
    strlen: function(a) {
        for (var t = 0, e = 0; e < a.length; e++) {
            var n = a.charCodeAt(e);
            n >= 1 && n <= 126 || 65376 <= n && n <= 65439 ? t++ : t += 2;
        }
        return t;
    },
    toast: function(a) {
        wx.showToast({
            icon: "none",
            title: a
        });
    },
    modal: function(a) {
        wx.showModal({
            title: "温馨提示",
            content: a,
            confirmColor: "#3196FA",
            showCancel: !1
        });
    },
    formatDateTime: function(a) {
        var t = new Date(a), e = t.getFullYear(), n = t.getMonth() + 1;
        n = n < 10 ? "0" + n : n;
        var o = t.getDate();
        o = o < 10 ? "0" + o : o;
        var i = t.getHours();
        i = i < 10 ? "0" + i : i;
        var s = t.getMinutes(), d = t.getSeconds();
        return s = s < 10 ? "0" + s : s, d = d < 10 ? "0" + d : d, e + "-" + n + "-" + o + " " + i + ":" + s + ":" + d;
    },
    getDateStr: function(a) {
        var t = new Date();
        return t.setDate(t.getDate() + a), t.getFullYear() + "-" + (t.getMonth() + 1 < 10 ? "0" + (t.getMonth() + 1) : t.getMonth() + 1) + "-" + (t.getDate() < 10 ? "0" + t.getDate() : t.getDate());
    },
    subMessage: function(a, t) {
        if (-1 == getApp().configApp.platform.indexOf("bdminapp")) {
            var e = getApp().globalData.minappmsg_tpls;
            e && e.length ? wx.requestSubscribeMessage ? wx.requestSubscribeMessage({
                tmplIds: e,
                success: function(n) {
                    if (console.log("订阅结果返回", n), n) {
                        for (var i = [], s = 0; s < e.length; s++) "accept" === n[e[s]] && i.push(e[s]);
                        i.length > 0 && o(a, i);
                    } else wx.showToast({
                        title: "授权订阅消息有误",
                        icon: "none"
                    });
                    "function" == typeof t && t(a);
                },
                fail: function(e) {
                    console.log("订阅失败提示：", e), 20004 == e.errCode || wx.showModal({
                        title: "提示",
                        content: e.errMsg,
                        showCancel: !1
                    }), "function" == typeof t && t(a);
                }
            }) : (wx.showToast({
                title: "微信版本过低，无法订阅",
                icon: "none"
            }), "function" == typeof t && t(a)) : "function" == typeof t && t(a);
        } else "function" == typeof t && t(a);
    },
    checkVersion: i
};